﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JYStockAnalyser.Face;

namespace JYStockAnalyser.WinUI
{
    public partial class FrmSecurityORder : FrmFunctionBase
    {
        public FrmSecurityORder()
        {
            InitializeComponent();
            this.comboBox1.SelectedIndex = 0;
        }

        private void FrmSecurityORder_Load(object sender, EventArgs e)
        {
            m_setGridStyle(this.dataGridView1);
        }

        /// <summary>
        /// 设置表格格式
        /// </summary>
        /// <param name="dgv"></param>
        void m_setGridStyle(DataGridView dgv)
        {
            dgv.AllowUserToAddRows = false;
            dgv.AllowUserToDeleteRows = false;
            dgv.AllowUserToResizeColumns = false;
            dgv.AllowUserToResizeRows = false;
            dgv.BackgroundColor = System.Drawing.Color.Black;
            dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
            dgv.AutoGenerateColumns = false;

            DataGridViewCellStyle headerCellstyle = new DataGridViewCellStyle();
            headerCellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            headerCellstyle.BackColor = System.Drawing.Color.Black;
            headerCellstyle.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            headerCellstyle.ForeColor = System.Drawing.Color.Aquamarine;
            headerCellstyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            headerCellstyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
            headerCellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            dgv.ColumnHeadersDefaultCellStyle = headerCellstyle;
            dgv.ColumnHeadersHeight = 35;
            dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;

            DataGridViewCellStyle defaultCellstyle = new DataGridViewCellStyle();
            defaultCellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            defaultCellstyle.BackColor = System.Drawing.Color.Black;
            defaultCellstyle.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            defaultCellstyle.ForeColor = System.Drawing.Color.Yellow;
            defaultCellstyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
            defaultCellstyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
            defaultCellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
            dgv.DefaultCellStyle = defaultCellstyle;

            dgv.EnableHeadersVisualStyles = false;
            dgv.GridColor = System.Drawing.Color.Gainsboro;
            dgv.ReadOnly = true;
            dgv.RowHeadersVisible = false;
            dgv.RowHeadersWidth = 4;
            dgv.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            dgv.RowTemplate.Height = 23;
            dgv.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;

            // 
            // Column1
            // 
            DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
            col1.DataPropertyName = "Order";
            DataGridViewCellStyle col1Cellstyle = new DataGridViewCellStyle();
            col1Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            col1Cellstyle.ForeColor = System.Drawing.Color.DeepSkyBlue;
            col1Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col1.DefaultCellStyle = col1Cellstyle;
            col1.HeaderText = "序号";
            col1.Name = "Column1";
            col1.ReadOnly = true;
            col1.Width = 80;
            // 
            // Column2
            // 
            DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();
            col2.DataPropertyName = "StockNO";
            DataGridViewCellStyle col2Cellstyle = new DataGridViewCellStyle();
            col2Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            col2Cellstyle.ForeColor = System.Drawing.Color.Red;
            col2Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col2.DefaultCellStyle = col2Cellstyle;
            col2.HeaderText = "股票代码";
            col2.Name = "Column2";
            col2.ReadOnly = true;
            col2.Width = 150;
            // 
            // Column3
            // 
            DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn();
            col3.DataPropertyName = "StockName";
            DataGridViewCellStyle col3Cellstyle = new DataGridViewCellStyle();
            col3Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
            col3Cellstyle.ForeColor = System.Drawing.Color.Red;
            col3Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col3.DefaultCellStyle = col3Cellstyle;
            col3.HeaderText = "股票名称";
            col3.Name = "Column3";
            col3.ReadOnly = true;
            col3.Width = 150;
            // 
            // Column4
            // 
            DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn();
            col4.DataPropertyName = "CurrentPrice";
            DataGridViewCellStyle col4Cellstyle = new DataGridViewCellStyle();
            col4Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            col4Cellstyle.ForeColor = System.Drawing.Color.Yellow;
            col4Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col4.DefaultCellStyle = col4Cellstyle;
            col4.HeaderText = "现价";
            col4.Name = "Column4";
            col4.ReadOnly = true;
            col4.Width = 100;
            //

            // 
            // Column5
            // 
            DataGridViewTextBoxColumn col5 = new DataGridViewTextBoxColumn();
            col5.DataPropertyName = "InsidePrice";
            DataGridViewCellStyle col5Cellstyle = new DataGridViewCellStyle();
            col5Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            col5Cellstyle.ForeColor = System.Drawing.Color.Yellow;
            col5Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col5.DefaultCellStyle = col5Cellstyle;
            col5.HeaderText = "内在价值";
            col5.Name = "Column5";
            col5.ReadOnly = true;
            col5.Width = 100;
            //

            // 
            // Column6
            // 
            DataGridViewTextBoxColumn col6 = new DataGridViewTextBoxColumn();
            col6.DataPropertyName = "GrowthString";
            DataGridViewCellStyle col6Cellstyle = new DataGridViewCellStyle();
            col6Cellstyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            col6Cellstyle.ForeColor = System.Drawing.Color.Yellow;
            col6Cellstyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
            col6.DefaultCellStyle = col4Cellstyle;
            col6.HeaderText = "上涨空间";
            col6.Name = "Column6";
            col6.ReadOnly = true;
            col6.Width = 120;
            //          

            dgv.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            col1,
            col2,
            col3,
            col4,
            col5,
            col6
            });

        }

        private void m_getData(string orderType, int pageIndex)
        {
            StockManageFace face = new StockManageFace();
            int pagecount = 0;
            this.dataGridView1.DataSource = face.GetOrderedSecurityOrderItems(orderType, pageIndex, 50, out pagecount);
            this.pager1.SetPageInfo(pageIndex, pagecount);
        }

        string currentOrderType = string.Empty;

        private void btnSearch_Click(object sender, EventArgs e)
        {
            currentOrderType = (string)this.comboBox1.SelectedItem;
            m_getData(currentOrderType, 1);
        }

        private void pager1_PageIndexChanged(JYStockAnalyser.ClientLib.PageIndexChangedEventArgs e)
        {
            m_getData(currentOrderType, e.NewPageIndex);
        }
    }
}
